package top.superflow.flow.runtime.inf

import top.superflow.exception.Exceptable

class ClassParamTypeSchema (clz : Class[_]) extends ParamTypeSchema with Exceptable{
  def getType: Any = clz

  def getCategory: SchemaCategory = {
    SchemaCategory.getSchemaCategory(SchemaCategory.CLASS_SCHEMA)
  }

  def isMatch(input: Any): Boolean = {
    if(input == null){
      return true
    }

    if(getType == null){
      throwRequestUnsupportedException("There is no type definition for the ClassParamTypeSchema")
    }

    if(!getType.isInstanceOf[Class[_]]){
      throwRequestUnsupportedException("The type for the schema should be java.lang.Class[?]")
    }

    this.getType.asInstanceOf[Class[_]].isAssignableFrom(input.getClass)
  }
}
